package com.sgl.gk.scheduled;

import com.sgl.gk.domain.GkHourComplete;
import com.sgl.gk.domain.GkStationConfigurationConnect;
import com.sgl.gk.mapper.GkHourCompleteMapper;
import com.sgl.gk.mapper.GkStationConfigurationConnectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @author:xuenci
 * @date:2023/2/16 10:18
 * 一小时完成数统计
 **/
@Component
public class OneHourTask {

    @Autowired
    GkStationConfigurationConnectMapper gkStationConfigurationConnectMapper;

    @Autowired
    GkHourCompleteMapper gkHourCompleteMapper;

    @Scheduled(cron = "0 0 0/1 * * ? ")
    public void init(){
        List<GkStationConfigurationConnect> gkStationConfigurationConnects = gkStationConfigurationConnectMapper.selectInfoByOenHour();
        int count = 0;
        for (GkStationConfigurationConnect gkStationConfigurationConnect : gkStationConfigurationConnects) {
            if (gkStationConfigurationConnect.getResult()==1) {
                count+=1;
            }
        }
        GkHourComplete gkHourComplete = new GkHourComplete();
        gkHourComplete.setCompleteNum(count);
        Date date = new Date();
        gkHourComplete.setCreateAt(date);
        gkHourComplete.setLastModifyAt(date);
        gkHourCompleteMapper.insert(gkHourComplete);
    }

}
